/**
 * FileName: CareController
 * Author:   P
 * Date:     2021/3/1 14:08
 * Description:
 */
package com.hospital.nurse.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hospital.nurse.pojo.Care;
import com.hospital.nurse.service.CareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/care")
@CrossOrigin
public class CareController {

    @Autowired
    private CareService careService;

    @RequestMapping("/allCare/{page}/{size}")
    public IPage<Care> allCare(@PathVariable int page , @PathVariable int size){
        IPage<Care> cares  =  new Page<>(page,size);
        cares = careService.page(cares);
        return cares;
    }


    @RequestMapping("/findCareById/{id}")
    public Care findCareById(@PathVariable int id){
        Care care = careService.getById(id);
        return care;
    }

    @RequestMapping("/findAllCareAndPatient/{page}/{size}")
    public Map<String,Object> findAllCareAndPatient(@PathVariable int page, @PathVariable int size){
        Map<String, Object> map = new HashMap<>();
        map.put("cares",careService.findAllCareAndPatient(page,size));

        return map;
    }


    //查看更多信息
    @RequestMapping("/queryCare/{id}")
    public Care findMoreCare(@PathVariable int id){
       // System.out.println(careService.findMoreCare(id));
        return  careService.findMoreCare(id);
    }

    //逻辑删除
    @RequestMapping("/deleteCare/{id}")
    public Map<String,Object> deleteCare(@PathVariable int id){
        Map<String, Object> map = new HashMap<>();
        careService.deleteCare(id);
        map.put("msg","删除成功");
        return map;
    }

    //根据姓名查询
    @RequestMapping("/getCares/{name}")
    public Map<String,Object> getCares(@PathVariable String name){
        System.out.println(name);
        Map<String, Object> map = new HashMap<>();
        map.put("cares",careService.getCareByName(name));
        return map;
    }

    @RequestMapping("/addCare")
    public Map<String,Object> addCare(@RequestBody Care care){
        Map<String, Object> map = new HashMap<>();
        map.put("msg",careService.addCare(care));
        return map;
    }


}
